﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Files.aspx.cs" Inherits="UpdateApp.Files" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
    <title>文件列表</title>
    <link href="CSS/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" />
    <style>
        .font {
            margin: 8px 10px;
            width: 8rem;
            font-size: 2rem;
        }

        html {
            height: 100%;
        }

        /* body {
            background-image: url(Images/bg<%=flag %>.jpg);
            background-size: 100% 100%;
            background-repeat: no-repeat;
            overflow: hidden;
        }*/
    </style>
</head>

<script src="JavaScript/Common.js"></script>
<script src="JavaScript/JQuery-1.9.1.min.js"></script>
<script src="CSS/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script>
    if (!isInnerIPFn()) {
        addScript();
    }
    else {
        $(function () {
            $(".thunder-link").hide();
        });
    }

    function addScript() {
        //console.log("外网 引入thunderurl")
        var script = document.createElement('script');
        script.setAttribute('type', 'text/javascript');
        script.setAttribute('src', '//open.thunderurl.com/thunder-link.js');
        document.getElementsByTagName('head')[0].appendChild(script);
    }
</script>

<body>
    <button type="button" class="btn btn-default font" onclick='window.location.href = "<%=file %>.aspx"'>上传</button>
    <table class="table table-hover" style="margin: 10px 20px; width: 97%; background-color: white; height: 10%; float: left; opacity: 0.8">
        <caption>文件列表</caption>
        <thead>
            <tr>
                <th id="op">操作</th>
                <th>文件</th>
                <th>大小</th>
                <th class="date">上传时间</th>
            </tr>
        </thead>
        <tbody>
            <tr style='display: <%=date == "" ? "" : "none" %>'>
                <td></td>
                <td><a href="?date=<%=alway %>">永久空间</a></td>
                <td></td>
                <td class="date"></td>
            </tr>
            <tr style='display: <%=date == "" ? "" : "none" %>'>
                <td></td>
                <td><a href="?date=<%=temp %>">临时空间</a></td>
                <td></td>
                <td class="date"></td>
            </tr>
            <% foreach (var item in list.Keys)
                { %>
            <tr>
                <td>
                    <div class="btn-group">
                        <button type="button" onclick="copyUrl(this)" value="<%=item%>" class="btn btn-info">复制链接</button>
                        <button type="button" class="btn btn-default"><a href="<%=path%>/<%=item%>" download="<%=item%>">下载</a></button>
                        <div class="btn-group">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                更多
                            <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <% if (IsEdit(item))
                                    { %>
                                <li><a href="Template.aspx?file=<%=path+"/"+item %>">
                                    <button type="button" class="btn btn-info">编辑</button></a></li>
                                <% } %>
                                <li><a href="?date=<%=date%>&name=<%=item %>" onclick="return confirm('确定要删除吗？')">
                                    <button type="button" class="btn btn-danger">删除</button></a></li>
                                 <% if (item.EndsWith("zip", true, null))
                                    { %>
                                <li><a href="?date=<%=date%>&name=<%=item %>&type=2">
                                    <button type="button" class="btn btn-info">解压</button></a></li>
                                <% } %>
                                <li><a href="?date=<%=date%>&alway=<%=item %>">
                                    <button type="button" class="btn btn-success">永久空间</button></a></li>
                                <li><a href="?date=<%=date%>&temp=<%=item %>">
                                    <button type="button" class="btn btn-warning">临时空间</button></a></li>
                                <li><a class="thunder-link" name="thunder" href="#" val="<%=path%>/<%=item%>">
                                    <button type="button" class="btn btn-primary">迅雷下载</button>
                                </a></li>
                            </ul>
                        </div>
                    </div>
                </td>
                <td><a href="<%=path%>/<%=item%>" target="_blank"><%=item%></a></td>
                <td><%=list[item].Split('|')[0]%></td>
                <td class="date"><%=list[item].Split('|')[1]%></td>
            </tr>
            <% } %>
        </tbody>
    </table>
</body>
</html>
<script>

    setTimeout(function () { window.close() }, 600000); //十分钟关闭

    function copyUrl(btn) {
        var inputTest = document.createElement('input')
        inputTest.value = window.location.origin + '/<%=path%>/' + encodeURI(btn.value)
        document.body.appendChild(inputTest)
        inputTest.select()
        document.execCommand('Copy')
        inputTest.className = 'oInput'
        inputTest.style.display = 'none'
        btn.className = "btn btn-success"
    }

    var browser = {
        versions: function () {
            var u = navigator.userAgent,
                app = navigator.appVersion;
            return {
                mobile: !!u.match(/AppleWebKit.*Mobile.*/),
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
                android: u.indexOf("Android") > -1 || u.indexOf("Linux") > -1,
                iPhone: u.indexOf("iPhone") > -1,
                iPad: u.indexOf("iPad") > -1
            };
        }(),
        language: (navigator.browserLanguage || navigator.language).toLowerCase()
    };

    //移动端隐藏上传时间
    if (browser.versions.mobile) {
        $("#op").css("width", "40%");
        $(".date").hide();
    } else
        $("#op").css("width", "20%");

    $(function () {
        //https://open.thunderurl.com/
        $("a[name=thunder]").click(function () {
            thunderLink.newTask({
                downloadDir: '',
                tasks: [{
                    name: '',
                    url: window.location.protocol + "//" + window.location.host + "//" + $(this).attr("val")
                }]
            });
        });
    });
</script>
